// test_element.js
// by SWC/SJX
// entry_function: start_element_test()

function element_style(i,kind){
	document.body.appendChild(i);
	var result="nothing";
	if(window.getComputedStyle){
		result= window.getComputedStyle(i,null)[kind] ;
	}
	else if(i.currentStyle){
		result= (i.currentStyle[kind]);
	}
	document.body.removeChild(i);
	return result;
}
function supports_elements_test(str){
	var i=document.createElement(str);
	return element_style(i,"display")=="block";
	/////section nav article aside hgroup header footer
}
function result_embedding_custom(){
	var i = document.createElement('div');
	i.setAttribute('data-test', 'sth');
	return ('dataset' in i) && ("test" in i.dataset);
}
function result_section_elements_test(para){
	var result=supports_elements_test(para);
	return result;
}
function result_grouping_content_elements(para){
	if(para!="ol"){
		return supports_elements_test(para);
	}
	else{
		var i=document.createElement("ol");
		if("reversed" in i)
			return true;
		else
			return false;
	}
}
function result_Textlevel_semantic_elements(para){	
	if(para=="mark"){
		var i =document.createElement("mark");
		var tmp=element_style(i,'backgroundColor')=="rgb(255, 255, 0)";
		return tmp;
		}
	else if(para=="rp"||para=="rt"||para=="ruby"){
		var contain = document.createElement('div');
		contain.innerHTML = "<ruby id='ruby1'><rp id='rp1'></rp><rt id='rt1'></rt></ruby>";
		document.body.appendChild(contain);
		var rubyElement = document.getElementById('ruby1');
		var rtElement = document.getElementById('rt1');
		var rpElement = document.getElementById('rp1');
		tmp=typeof HTMLElement != 'undefined';
		if(para=="rp")
			return tmp&&element_style(rpElement,"display")=='none';
		if(para=="rt")
			return tmp&&element_style(rtElement,"display")=='ruby-text';
		if(para=="ruby")
			return tmp&&element_style(rubyElement,"display")=='ruby';
	}
	else if(para=="time"||para=="datatime"){
		i=document.createElement("time");
		tmp=(typeof HTMLTimeElement != 'undefined' && i instanceof HTMLTimeElement);
		if(para=="time")
			return tmp;
		if(para=="datatime"){
			if("datetime" in i)
				return true;
			else
				return false;
			}
	}
	else if(para=="wbr"){
		i=document.createElement("wbr");
		tmp=(typeof HTMLElement != 'undefined' && i instanceof HTMLElement);
		return tmp;
	}
}
function result_interactive_elements(para1,para2){
	var i=document.createElement(para1)
	if(para2 in i||supports_elements_test(para2))
		return true;
	else
		return false;
}
function result_global_attributes_or_methods(para){
	var i=document.createElement("a");
	if(para!="insertAdjacentHTML"){
		if(para in i)
			return true;
		else
			return false;
	}
	else{
		if(i.insertAdjacentHTML)
			return true;
		else
			return false;
	}
}
function start_element_test() {
	E = {
		layerName: "Element Test",
		type: 	"aggrg",
		nlist: {
			embedding_custom: {
				layerName: "Embedding Custom",
				type: "aggrg",
				nlist: {"non-visible data": result_embedding_custom()}
			},
			section_elements: {
				layerName: "Section Elements",
				type: "aggrg",
				nlist: {	
					"section element":result_section_elements_test("section"),
					"nav element":result_section_elements_test("nav"),
					"article element":result_section_elements_test("article"),
					"aside element":result_section_elements_test("aside"),
					"hgroup element":result_section_elements_test("hgroup"),
					"header element":result_section_elements_test("header"),
					"footer element":result_section_elements_test("footer")}
			},
			grouping_content_elements: {
				layerName: "Grouping Content Elements",
				type: "aggrg",
				nlist: {
					"figure element":result_grouping_content_elements("figure"),
					"figcaption element":result_grouping_content_elements("figcaption"),
					"reversed attribute on the ol element":result_grouping_content_elements("ol")
				}
			},
			textlevel_semantic_elements: {
				layerName: "Textlevel Semantic Elements",
				type: "aggrg",
				nlist: {
					"mark element":result_Textlevel_semantic_elements("mark"),
					"rp element":result_Textlevel_semantic_elements("rp"),
					"rt element":result_Textlevel_semantic_elements("rt"),
					"ruby element":result_Textlevel_semantic_elements("ruby"),
					"time element":result_Textlevel_semantic_elements("time"),
					"datetime attribute in time element":result_Textlevel_semantic_elements("datatime"),
					"wbr element":result_Textlevel_semantic_elements("wbr")
				}
			},
			interactive_elements:{
				layerName: "Interactive Elements",
				type: "aggrg",
				nlist: {
					"details element":result_interactive_elements("details","open"),
					"summary element":result_interactive_elements("summary","summary"),
					"command element":result_interactive_elements("command","type"),
					"menu element":result_interactive_elements("menu","type")
				}
			},
			global_attributes_or_methods:{
				layerName: "Global Attributes or Methods",
				type: "aggrg",
				nlist: {
					"hidden attribute":result_global_attributes_or_methods("hidden"),
					"outerHTML property":result_global_attributes_or_methods("outerHTML"),
					"insertAdjacentHTML function":result_global_attributes_or_methods("insertAdjacentHTML")
				}
			}
		}
	}
	return E;
}
